<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>重新发起衔接</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:150px;
        }
        input {
            width:200px;
        }
        table {
            border-collapse:separate;
        }
        .redText {
            color:red;
        }
    </style>
</head>
<body>
<div class="mini-fit" style="padding-top:50px;margin-bottom:45px;">
    <form id="form1" method="post">
        <#--唯一标识id-->
        <input name="id" id="id" class="mini-hidden" value="${id!''}" readonly />
        <#--罪犯编号-->
        <input name="priNum" id="priNum" class="mini-hidden" value="${priNum!''}" readonly />
        <!-- 用户 编辑框START-->
        <table class="form-table" align="center" cellspacing="8">
            <tr>
                <td class="discell">姓名:</td>
                <td>
                    <input class="mini-textbox" required="true" emptyText="请输入..." id="pName" name="pName" value="${pName!''}" enabled="false" />
                </td>
                <td class="discell"><font color="#dc143c">*</font>衔接途径:</td>
                <td>
                    <input name="tujing" id="tujing" class="mini-combobox"
                           url="/search/code/native?1=1&codeType=1_43&pcodeId=-1"
                           textField="text" valueField="id" value="01" required="true" emptyText="请选择..." value="${Tujing!''}" />
                </td>
            </tr>
            <tr>
                <td class="discell"><font color="#dc143c">*</font>帮教对象类别:</td>
                <td>
                    <input name="type" id="type" class="mini-combobox"
                           url="/search/code/native?1=1&codeType=1_13&pcodeId=-1"
                           textField="text" valueField="id" required="true" emptyText="请选择..." value="${pinggu!''}" enabled="false" />
                </td>
                <td class="discell"><font color="#dc143c">*</font>帮教对象衔接方式:</td>
                <td>
                    <#if pinggu == "02">
                        <#if wushe== '01' && (shehei=='true' || shekong=='true')>
                        <#--监狱送回-->
                            <input name="yiban" id="yiban" class="mini-combobox" onvaluechanged="chooseName1()"
                                   url="/search/code/native?1=1&codeType=1_44_1&pcodeId=-1"
                                   textField="text" valueField="id" required="true" emptyText="请选择..." />
                        <#else>
                        <#--基层组织及家属接回，人员自返-->
                            <input name="yiban" id="yiban" class="mini-combobox"
                                   url="/search/code/native?1=1&codeType=1_44_3&pcodeId=-1" onvaluechanged="chooseName1()"
                                   textField="text" valueField="id" required="true" emptyText="请选择..." />
                        </#if>
                    <#else>
                        <#if (weifa ?? && weifa=='1') || (Aftype ?? && Aftype=='1')>
                        <#--监狱送回-->
                            <input name="zhongdian" id="zhongdian" class="mini-combobox" onvaluechanged="chooseName2()"
                                   url="/search/code/native?1=1&codeType=1_44_1&pcodeId=-1"
                                   textField="text" valueField="id" required="true" emptyText="请选择..." />
                        <#else>
                        <#--基层组织及家属接回，监狱送回-->
                            <#if (SANJIA ?? && SANJIA== '1') && (Sanwu ?? && Sanwu=='1')>
                            <#--基层组织及家属接回，监狱送回-->
                                <input name="zhongdian" id="zhongdian" class="mini-combobox" onvaluechanged="chooseName2()"
                                       url="/search/code/native?1=1&codeType=1_44_4&pcodeId=-1"
                                       textField="text" valueField="id" required="true" emptyText="请选择..." />
                            <#elseif (SANJIA ?? && SANJIA=='1') && (SANJIA ?? && Sanwu!='1')>
                            <#--基层组织及家属接回，监狱送回-->
                                <input name="zhongdian" id="zhongdian" class="mini-combobox" onvaluechanged="chooseName2()"
                                       url="/search/code/native?1=1&codeType=1_44_4&pcodeId=-1"
                                       textField="text" valueField="id" required="true" emptyText="请选择..." />
                            <#elseif (SANJIA ?? && SANJIA!='1') && (Sanwu ?? && Sanwu=='1')>
                            <#--基层组织及家属接回-->
                                <input name="zhongdian" id="zhongdian" class="mini-combobox" onvaluechanged="chooseName2()"
                                       url="/search/code/native?1=1&codeType=1_44_2&pcodeId=-1"
                                       textField="text" valueField="id" required="true" emptyText="请选择..." />
                            </#if>
                        </#if>
                    </#if>
                </td>
            </tr>

            <tr>
                <td class="discell">
                    <font color="#dc143c">*</font>
                    <#--用户判断-->
                    <#if (level=='01')>
                        监狱联系人:
                    <#elseif (level== '02')>
                        看守所联系人:
                    <#else >
                        社矫中心联系人:
                    </#if>
                </td>
                <td>
                    <input class="mini-textbox" required="true" emptyText="请输入..." id="lianxiren" name="lianxiren" value="${lianxiren!''}" />
                </td>
                <td>
                    <input class="mini-hidden" name="sj" id="sj" value="${JHSJ!''}">
                    <input class="mini-hidden" name="dd" id="dd" value="${JHDD!''}">
                </td>
            </tr>
            <tr>
                <td class="discell">
                    <#if (level=='01')>
                        监狱固话:
                    <#elseif (level== '02')>
                        看守所固话:
                    <#else >
                        社矫中心固话:
                    </#if>
                </td>
                <td>
                    <input class="mini-textbox"  emptyText="请输入固定电话" onblur="checkPhone(2)" id="tel" name="tel"
                           value="${tel!''}" />
                </td>
                <td class="discell">
                    <#if (level=='01')>
                        监狱手机号码:
                    <#elseif (level== '02')>
                        看守所手机号码:
                    <#else >
                        社矫中心手机号码:
                    </#if>
                </td>
                <td>
                    <input class="mini-textbox"  emptyText="请输入手机号码" onblur="checkPhone(1)" id="phone" name="phone"
                           value="${phone!''}" />
                </td>
            </tr>
            <tr id="tr1">
                <td class="discell"><font color="#dc143c">*</font>接回时间:</td>
                <td class="input">
                    <input property="editor" class="mini-datepicker" id="JHSJ" name="JHSJ" value="${JHSJ!''}" allowInput="false" style="width: 54%;" />
                </td>
                <td class="discell"><font color="#dc143c">*</font>接回地点:</td>
                <td>
                    <input class="mini-textbox" required="true" emptyText="请输入..." id="JHDD" name="JHDD" value="${JHDD!''}" onblur="changeDD"/>
                </td>
            </tr>
            <tr  id="tr2" style="display: none">
                <td class="discell"><font color="#dc143c">*</font>送回时间:</td>
                <td class="input">
                    <input property="editor" class="mini-datepicker" id="SHSJ" name="SHSJ" value="${JHSJ!''}" allowInput="false" style="width: 54%;" />
                </td>
                <td class="discell"><font color="#dc143c">*</font>
                    送回地点:
                </td>
                <td>
                    <input class="mini-textbox" required="true" emptyText="请输入..." id="SHDD" name="SHDD" value="${JHDD!''}" onblur="changeDD"/>
                </td>
            </tr>
            <tr  id="tr3" style="display: none">
                <td class="discell"><font color="#dc143c">*</font>返回时间:</td>
                <td class="input">
                    <input property="editor" class="mini-datepicker" id="FHSJ" name="FHSJ" allowInput="true" value="${JHSJ!''}" style="width: 54%;" />
                </td>
                <td class="discell">
                    返回地点:
                </td>
                <td>
                    <input class="mini-textbox"  emptyText="请输入..." id="FHDD" name="FHDD" value="${JHDD!''}" onblur="changeDD"/>
                </td>
            </tr>

            <tr>
                <td class="discell">刑满释放人员通知书:</td>
                <td>
                    <input type="button" onclick="onFileUpload()" value="上传" style="width: 150px" />
                    <span id="msg1"></span>
                    <div><b>支持扩展名:</b>.rar .zip .doc .docx .xls .xlsx .pdf .jpg</div>
                </td>
            </tr>
            <tr>
                <td class="discell">司法所信息</td>
                <td colspan="3"><font color="#1e90ff">${sfsinfo!''}</font></td>
            </tr>
        </table>
    </form>
</div>
<div style="width:100%;position:absolute;bottom:0;line-height: 45px;border-top: 1px solid #dfdfdf;text-align: center">
    <a class="mini-button" iconCls="fa-save" plain="true" style="font-size: 15px" onclick="saveData()">发起衔接</a>
</div>
<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    window.onload = function (){
        $('#msg1').text("上传成功" + ${count1!''} + "条!")
    }

    function saveData() {
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        //送回时间和接回时间处理
        var sj = mini.get("sj").getValue();
        mini.get("JHSJ").setValue(sj);
        var dd = mini.get("dd").getValue();
        mini.get("JHDD").setValue(dd);
        // 校验电话号码
        var tel = mini.get("tel").getValue();
        var phone = mini.get("phone").getValue();
        var newPhone = checkTelAndPhone(tel,phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        tel = newPhone['newTelAndPhone'];
        if('-1'===kflag){
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if(!flag){
            mini.alert("固定电话或手机号码有误，请重填");
            return;
        }
        var data = form.getData();
        data.taskId = "12";
        var json = mini.encode(data);
        $.ajax({
            url: "/azbj/yazgl/xj/updateXj",
            data: {data: json},
            type: "post",
            success: function (success) {
                if (success.code == 1) {
                    mini.alert("保存成功", "成功", window.CloseOwnerWindow);
                } else if (success.code == 4001) {//根据后台判断是否上传了刑满释放人员通知书
                    mini.alert("请上传刑满释放人员通知书！");
                }else if (success.code == 5599) {
                    mini.alert(success.message);
                }  else {
                    mini.alert("保存失败");
                }
            }
        })
    }

    // 上传附件
    function onFileUpload() {//taskId为2是衔接信息的附件
        commonEdit("/upload/user/uploadAppendixfile/view?1=1&id=${id!''}&priNum=${priNum!''}&taskId=12", null, null, 600, 400, true, true, true,callback);
        function callback(){
            $.ajax({
                url: "/upload/downloadAppendixFile/getCountall?1=1&priNum="+${priNum!''}+"&taskId=12",
                type: "get",
                success: function(success){
                    $("#msg1").text("上传成功" + success.data + "条!");
                }
            })
        }
    }


    function closeParentWindows(action) {
        if (window.parent.CloseOwnerWindow) {
            return window.parent.CloseOwnerWindow(action);
        } else {
            window.parent.close();
        }
    }

    /*
        衔接流程-选择监狱送回，应该为送回时间和送回地点
        一般帮教对象的监狱送回变更
     */
    function chooseName1(){
        var yiban = mini.get("yiban");
        if(yiban.getValue() == "04") { //04为人员自返
            document.getElementById("tr1").style.display = "none";
            document.getElementById("tr2").style.display = "none";
            document.getElementById("tr3").style.display = "";
        }else if (yiban.getValue() == '01'){    //01为监狱送回
            document.getElementById("tr1").style.display = "none";
            document.getElementById("tr2").style.display = "";
            document.getElementById("tr3").style.display = "none";
        }else {
            document.getElementById("tr1").style.display = "";
            document.getElementById("tr2").style.display = "none";
            document.getElementById("tr3").style.display = "none";
        }
    }

    /*
        衔接流程-选择监狱送回，应该为送回时间和送回地点
        重点帮教对象的监狱送回变更
     */
    function chooseName2(){
        var zhongdian = mini.get("zhongdian");
        if(zhongdian.getValue() == "06" || zhongdian.getValue() == "01") { //06和01为监狱送回
            document.getElementById("tr1").style.display = "none";
            document.getElementById("tr2").style.display = "";
            document.getElementById("tr3").style.display = "none";
        }else{
            document.getElementById("tr1").style.display = "";
            document.getElementById("tr2").style.display = "none";
            document.getElementById("tr3").style.display = "none";
        }
    }

    /**
     * 将改变后的日期同步到隐藏sj中
     * @param e 对象
     */
    function onDrawDate(e) {
        mini.get("sj").setValue(e.sender.text);
    }

    /**
     * 将改变后的地点同步到隐藏dd中
     * @param e 对象
     */
    function changeDD(e){
        mini.get("dd").setValue(e.sender.value);
    }

    /**
     * 校验手机号码
     * @param e 参数 1-手机 2-固话
     * @returns {boolean} 返回校验结果
     */
    function checkPhone(e){
        var phone = mini.get("phone").getValue();
        var tel = mini.get("tel").getValue();
        if(e=='1'){
            if(phone != '' && !(/^1[3456789]\d{9}$/.test(phone))){
                mini.alert("手机号码有误，请重填");
                return false;
            }
        }
        if(e=='2'){
            if(tel != '' && !/^((0\d{2,3})-?)(\d{7,8})$/.test(tel)){
                mini.alert('固定电话有误，请重填');
                return false;
            }
        }
    }
</script>
</body>
</html>